package com.ellricky.excute_president.ui.activity.meet

import android.view.View
import com.andr.common.http.callback.JOCallback
import com.andr.common.ui.activity.BaseToolBarActivity
import com.andr.common.ui.mvp.BasePresenter
import com.andr.common.util.EmptyUtil
import com.andr.common.util.ToastUtil
import com.ellricky.baselib.BaseConstant
import com.ellricky.baselib.http.HttpUtils
import com.ellricky.baselib.util.EAppUtil
import com.ellricky.excute_president.API_AM_MEETING_ADD
import com.ellricky.excute_president.R
import kotlinx.android.synthetic.main.pd_activity_ammeeting_add.*
import org.json.JSONObject

class AmMeetingAddActivity : BaseToolBarActivity<Void, BasePresenter<Void>>() {

    override fun getContentLayout(): Int {
        return R.layout.pd_activity_ammeeting_add
    }

    override fun initUIView() {
        super.initUIView()
        mTvTitle.text = getString(R.string.pd_am_add)
        btnSubmit.setOnClickListener(this)
    }


    override fun onClickView(v: View?) {
        super.onClickView(v)
        when (v) {
            btnSubmit -> postSubmit()
        }
    }


    private fun postSubmit() {
        val theme = etTheme.value
        val content = etContent.value
        if (EmptyUtil.isEmpty(theme)) {
            ToastUtil.show(this, R.string.pd_am_theme_input)
            return
        }
        /* if (EmptyUtil.isEmpty(person))  {
             ToastUtil.show(this, R.string.pd_am_fz_person_sel)
             return
         }
         if (EmptyUtil.isEmpty(date)) {
             ToastUtil.show(this, R.string.pd_am_select_date_sel)
             return
         }*/
        if (EmptyUtil.isEmpty(content)) {
            ToastUtil.show(this, R.string.pd_am_content_input)
            return
        }


        val url = EAppUtil.getApiHost() + API_AM_MEETING_ADD
        val paramMap = mutableMapOf<String, Any>(
                "title" to theme,
                "meetInfo" to content
        )
        HttpUtils.getInstance().post(url, paramMap, object : JOCallback(this) {
            override fun onSuccess(dataJO: JSONObject?, msg: String?) {
                setResult(BaseConstant.RESULT_CODE_ADD)
                finish()
            }
        })
    }

}

